<?php 

	$data  = json_decode($_GET['data'],true);
	$openid = $data['openid'];
	$title = $data['title'];
	$price = $data['price'];
	$url = $data['url'];
	sendMessage($openid,$title,$price,$url);
 //微信接口调用凭证
    function voucher_token(){  
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx2de38da107527240&secret=446fdd6335e31f0ceeaf63562ff03a4c";
            $access_token = json_decode(file_get_contents($url),true);
            return $access_token;
    }

//通过公众号向此用户发送模板消息告知绑定成功
    function sendMessage($openid,$title,$price,$url_request){
        $access_token = voucher_token();
        $token = $access_token['access_token'];
        $url="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$token;
        $post_data = array(
                "touser"=>$openid,
                "template_id"=>"pBJKUxbUvRenf5pUH5z1I_o8l-2w3j70VtH-hFyCqwE",
                "url"=>$url_request,    
                "data"=> array(
                        "first" => array(
                            "value"=>"请确认以下订单信息",
                            "color"=>"#173177"
                            ),
                        "keyword1"=>array(
                            "value"=>$title,
                            "color"=>"#173177"
                            ),
                        "keyword2"=>array(
                            "value"=>$price,
                            "color"=>"#173177"
                            ),
                        "keyword3"=> array(
                            "value"=>date('Y-m-d H:i:s'),
                            "color"=>"#173177"
                            ),
                        "keyword4"=> array(
                            "value"=>"订单有效时间为10分钟，请您尽快完成支付",
                            "color"=>"#173177"
                            ),
                        "remark"=> array(
                            "value"=>"点击支付订单",
                            "color"=>"#173177"
                            ),
                )
        );
        return curl_post($url,json_encode($post_data));
    }
    //模拟post请求
    function curl_post($url,$data){ // 模拟提交数据函数
        $ch = curl_init ();
        curl_setopt ( $ch, CURLOPT_URL, $url );
        curl_setopt ( $ch, CURLOPT_POST, 1 );
        curl_setopt ( $ch, CURLOPT_HEADER, 0 );
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
        $return = curl_exec ( $ch );
        curl_close ( $ch );
        return $return;
    }

 ?>